//
//  KVUserAccountModel.swift
//  KVBestMicroblog
//
//  Created by 李康卫 on 16/7/21.
//  Copyright © 2016年 李康卫. All rights reserved.
//

import UIKit

class KVUserAccountModel: NSObject,NSCoding {
    /*
    "access_token" = "2.00ttMxKGLaI1sC57ab3f866cZlLkRB";
    "expires_in" = 157679999;
    "remind_in" = 157679999;
    uid = 5658671297; */
    ///用户的token
    var access_token: String?
    ///使用的期限
    var expires_in: NSTimeInterval = 0
    //用户id
    var uid: String?
    //初始化方法
    ///screen_name	string	用户昵称
    var screen_name: String?
    ///avatar_large	string	用户头像地址（大图），180×180像素
    var avatar_large: String?
    
    init(dict: [String: AnyObject]) {
//       self.access_token = dict["access_token"] as! String
//        expires_in = dict["expires_in"] as! NSTimeInterval
//        uid = dict["uid"] as! String
        super.init()
        //kvc的方式为属性福赋值
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
//        print(value!)
    }
    
    //描述是一个属性
    override var description: String {
        get {
            return "access_token: \(access_token),expires_in: \(expires_in),uid\(uid)"
        }
    }
    
    //实现解码编码协议
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeDouble(expires_in, forKey: "expires_in")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
    }
    required init?(coder aDecoder: NSCoder) {
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        expires_in = aDecoder.decodeDoubleForKey("expires_in")
        uid = aDecoder.decodeObjectForKey("uid") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        
        super.init()
    }
    
}

//实现解码编码协议
//extension KVUserAccountModel: NSCoding {
//    func encodeWithCoder(aCoder: NSCoder) {
//        aCoder.encodeObject(access_token)
//    }
//}
